// Marty Stepp, CSE 142 Winter 2008, Section XYZ // // This program draws a figure that looks like a mirror // using nested loops. // // It also has a class constant for the mirror size so // I can resize the mirror by changing the constant's value. public class Mirror { // a constant for the figure's size public static final int SIZE = 4; public static void main(String[] args) { topHalf(); bottomHalf(); } // This method draws the top half of the mirror. public static void topHalf() { for (int line = 1; line <= SIZE; line++) { // | System.out.print("|"); // spaces for (int space = 1; space <= (-2 * line + 2*SIZE); space++) { System.out.print(" "); } // <> System.out.print("<>"); // dots for (int dot = 1; dot <= (4 * line - 4); dot++) { System.out.print("."); } // <> System.out.print("<>"); // spaces for (int space = 1; space <= (-2 * line + 2*SIZE); space++) { System.out.print(" "); } // | System.out.println("|"); } } // This method draws the bottom half of the mirror. public static void bottomHalf() { for (int line = SIZE; line >= 1; line--) { System.out.print("|"); for (int space = 1; space <= (-2 * line + 2*SIZE); space++) { System.out.print(" "); } System.out.print("<>"); for (int dot = 1; dot <= (4 * line - 4); dot++) { System.out.print("."); } System.out.print("<>"); for (int space = 1; space <= (-2 * line + 2*SIZE); space++) { System.out.print(" "); } System.out.println("|"); } } }